const express = require('express');
const router = express.Router();
const { addNewPoint, getTimeLine } = require('../controller/timeline');
const {SuccessModel, ErrorModel} = require('../model/resModel');
const rootCheck = require('../middleWare/rootCheck');
const loginCheck = require('../middleWare/loginCheck');

router.post('/addNewPoint', loginCheck, rootCheck, async (req, res, next) => {
  const data = req.body;
  const result = await addNewPoint(data.createTime, data.content);
  if (result) {
    res.json(new SuccessModel('写入成功！'));
  } else {
    res.json(new ErrorModel('添加timePoint失败'));
  }
});

router.get('/getTimeLine', async (req, res, next) => {
  try {
    const result = await getTimeLine();
    res.json(new SuccessModel(result));
  } catch (err) {
    res.json(new ErrorModel('获取timeline失败！'))
  }
});
module.exports = router;